import loadable from '@loadable/component'
import {Route, Switch, HashRouter, Redirect} from 'react-router-dom'
import {Provider} from 'react-redux'
import store from '@/store2'

const Laylout = loadable(() => import('@/component/layout'))
const Login = loadable(() => import('@/component/login'))

const token = () => localStorage.getItem('token')

export default () => (
  <div className="app">
    <HashRouter>
      <Provider store={store}>
        <Switch>
          <Route path="/dash" render={() => {
            return token() ? <Laylout /> : <Redirect to="/login"/>
          }} />
          <Route path="/login" render = {() => {
            return token() ? <Redirect to='/dash'/> : <Login />
          }} />
          <Redirect to="/dash/404"/>
        </Switch>
      </Provider>
    </HashRouter>
  </div>
)